# -*- coding: utf-8 -*-
# @Time : 2022/6/29 下午5:15
# @Author : wyf
# @FileName: qm.py
# @Email: yunfei.wang@innvote.com
import execjs
import requests

headers = {
    "accept": "application/json, text/plain, */*",
    "accept-encoding": "gzip, deflate, br",
    "accept-language": "zh-CN,zh;q=0.9",
    "cache-control": "no-cache",
    # "cookie": "PHPSESSID=inglmqhqmq26gn1gebuvcs5fkt; Hm_lvt_ff3eefaf44c797b33945945d0de0e370=1656490891; qm_check=SxJXQEUSChd2fHd1dRQQeV5EVVwcEHxZRlVVGGYREHlCWUMYYhwXalUZd0ZZQFhZU0MQdFxFV1NNA3AJARBGQ28FbwUXQkNmBWsIHBB0A3QBARwVHhJaWFFbWxIKEgAcABkHHgAVABZF; gr_user_id=51719096-cc9c-49af-b510-961c4c2d6330; ada35577182650f1_gr_session_id=7d1602d8-0baa-4033-aaf6-da52604c0ac0; ada35577182650f1_gr_session_id_7d1602d8-0baa-4033-aaf6-da52604c0ac0=true; syncd=307; Hm_lpvt_ff3eefaf44c797b33945945d0de0e370=1656493086; synct=1656493102.011",
    "origin": "https://www.qimai.cn",
    "pragma": "no-cache",
    "referer": "https://www.qimai.cn/",
    "sec-ch-ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"102\", \"Google Chrome\";v=\"102\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"Windows\"",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-site",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36"
}

# url = "https://api.qimai.cn/rank/index"
url = "https://api.qimai.cn/rank/release"

params = {
    "genre": "36",
    "country": "cn",
    "date": "2022-07-31",
    "is_preorder": "all",
    "status": "3",
    "sdate": "2022-07-31",
    "edate": ""
}

data = execjs.compile(open('./qm.js').read()).call("data", url, params)
print(data)

req = requests.get(url=data.get("url"), params=params, headers=headers)
print(req.json())




